home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / PIL / ImageWin.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  1.3 KB  |  58 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id: ImageWin.py,v 1.1.1.1 1998/08/18 13:07:56 sjoerd Exp $
  4. #
  5. # a Windows DIB display interface
  6. #
  7. # History:
  8. #    96-05-20 fl    Created
  9. #    96-09-20 fl    Fixed subregion exposure
  10. #    97-09-21 fl    Added draw primitive (for tzPrint)
  11. #
  12. # Copyright (c) Secret Labs AB 1997.
  13. # Copyright (c) Fredrik Lundh 1996-97.
  14. #
  15. # See the README file for information on usage and redistribution.
  16. #
  17.  
  18. import Image
  19.  
  20. #
  21. # Class wrapper for the Windows display buffer interface
  22. #
  23. # Create an object of this type, paste your data into it, and call
  24. # expose with an hDC casted to a Python int...  In PythonWin, you
  25. # can use the GetHandleAttrib() method of the CDC class to get an
  26. # appropriate hDC.
  27. #
  28.  
  29. class Dib:
  30.  
  31.     def __init__(self, mode, size):
  32.     if mode not in ["1", "L", "P", "RGB"]:
  33.         mode = "RGB"
  34.     self.image = Image.core.display(mode, size)
  35.     self.mode = mode
  36.     self.size = size
  37.  
  38.     def expose(self, dc):
  39.     return self.image.expose(dc)
  40.  
  41.     def draw(self, dc, dst, src = None):
  42.         if not src:
  43.             src = (0,0) + self.size
  44.     return self.image.draw(dc, dst, src)
  45.  
  46.     def query_palette(self, dc):
  47.     return self.image.query_palette(dc)
  48.  
  49.     def paste(self, im, box = None):
  50.     # fix to handle conversion when pasting
  51.     im.load()
  52.     if self.mode != im.mode:
  53.         im = im.convert(self.mode)
  54.     if box:
  55.         self.image.paste(im.im, box)
  56.     else:
  57.         self.image.paste(im.im)
  58.